<!DOCTYPE html>
<html>
<head>
	<title>title</title>
	<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
</head>
<body>
    <div id="ids" style="font-size:50px">今天天气不错</div>
    <button onclick="callLogin()" style="font-size:100px">我是按钮</button>
</body>
<script type="text/javascript">
	$(function(){
		setCookie("jsToken","abcdefg");
	});

	function JSBridge(msg){
		alert(msg);
	}

//我们往网页里注入的js代码
function callLogin() {
    try{
		// APPJS是我们所注入的对象
	    window.webkit.messageHandlers.APPJS.postMessage("shouldLogin");
    }catch(err){

    }
}

function setHTMLDiv(name){
	$("#ids").html(name);
}


	function getCookie(name){
		var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)"); //正则匹配
	    if(arr=document.cookie.match(reg)){
	      return unescape(arr[2]);
	    }
	    else{
	     return null;
	    }
	}

	/**
	* 设置cookie
	 * @param name cookie的名称
	 * @param value cookie的值
	 * @param day cookie的过期时间
	 */
	var setCookie = function (name, value, day) {
	  if(day !== 0){     //当设置的时间等于0时，不设置expires属性，cookie在浏览器关闭后删除
	    var expires = day * 24 * 60 * 60 * 1000;
	     var date = new Date(+new Date()+expires);
	     document.cookie = name + "=" + escape(value) + ";expires=" + date.toUTCString();
	   }else{
	     document.cookie = name + "=" + escape(value);
	   }
	 };


</script>
</html>
